<?php
/**
 * Created by PhpStorm.
 * User: changyifan
 * Date: 2018/1/29
 * Time: 下午4:34
 * 知识点
 */

namespace Home\Model;
use Think\Model\BaseModel;

class PointModel extends BaseModel{

//    protected $course_id;

    protected $_link = array(
          'Course' => array(
              'mapping_type' => self::BELONGS_TO,
//              'class_name' => 'Course',
              'foreign_key' => 'cou_id',

              'mapping_fields' => 'cou_name',
              'as_fields' => 'name'
          )
    );


    public function getPointInfoListByAll(){
        $result = $this->select();

        if($result){
            return $result;
        }else{
            return array();
        }

    }

    protected $_scope = array(
        'Course' => array(
            'where' => array('cou_id'=> ''),

        )
    );
    protected $_map = array(
        'knowledge_id' => 'poi_id',
        'knowledge_content' => 'poi_content',
        //'course_name' => 'cou_id'
    );

    public function getPointListByCourse(){
        $teachercourse = D('Teachercourse','Model');
        $course_info = $teachercourse->getTeacherCourseNounInfoListWithCurrentTeacher();
        $con = array();
        foreach ($course_info as $key => $value){
            $con[$key] = $value['cou_id'];
        }
        $cou_id = array('in',$con);
        $info = $this->where(array('cou_id'=> $cou_id))->select();
        return $info ? $info : array();
    }
    public function getPointInfoListWithCourseName($course_id){

        if ($course_id == 0){
            $course_id = array('like','%%');
        }
        $result = $this-> scope('Course',array('where'=>array('cou_id'=>$course_id))) -> relation(true) -> select();
        if($result){
            return $result;
        }else{
            return array();
        }
    }





}